# Requires
require 'yaml'
require 'active_record'

# Requires to scheduler
require 'rubygems'
require 'openwfe/util/scheduler'

module RadiaStore
  LIBRARIES = File.dirname(__FILE__) unless defined? LIBRARIES
  CONFIGURATION_DIR = File.dirname(__FILE__) + '/../config' unless defined? CONFIGURATION_DIR
  DB_CONFIG = CONFIGURATION_DIR + '/database.yml' unless defined? DB_CONFIG
  APP_CONFIG_FILE = CONFIGURATION_DIR + '/application.yml' unless defined? APP_CONFIG_FILE
  LOG = File.dirname(__FILE__) + '/../log/application.log' unless defined? LOG

  db_properties = YAML.load_file RadiaStore::DB_CONFIG

  if defined? PRODUCTION
    database = 'database_production'
  elsif defined? TEST
    database = 'database_test'
  else
    database = 'database_development'
  end

  begin
    ActiveRecord::Base.establish_connection(db_properties[database])
  rescue
    "Can't connect to database. Database: #{database}"
  end

  # Load principal files
  require RadiaStore::LIBRARIES + '/audio_asset'
  require RadiaStore::LIBRARIES + '/replica_system'
  require RadiaStore::LIBRARIES + '/replica'
  require RadiaStore::LIBRARIES + '/fetcher'
  require RadiaStore::LIBRARIES + '/storage_manager'
end